<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">

<head th:replace="common/head::head">
</head>

<body>
<div class="layui-row">
    <button onclick="location.reload();" class="layui-btn layui-btn-sm">刷新表格</button>

    <button onclick="editItem('');" class="layui-btn layui-btn-sm">添加模板</button>
    <button id="import" class="layui-btn layui-btn-sm">导入模板</button>

</div>
<div class="layui-form">
    <table class="layui-table">
        <thead>
        <tr>
            <th>模板ID</th>
            <th>模板名称</th>
            <th>修改时间</th>
            <th>最后执行人</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="item : ${array}">
            <td th:text="${item.id}"></td>
            <td th:text="${item.name}"></td>
            <td th:text="${item.modifyTime}"></td>
            <td th:text="${item.lastRunUser}"></td>
            <td>
                <button th:sId="${item.id}" onclick="runScript(this)" class="layui-btn layui-btn-warm layui-btn-sm">执行
                </button>
                <button th:sId="${item.id}" text="修改"
                        onclick="editItem(this)"
                        class="layui-btn layui-btn-sm">修改
                </button>

            </td>
        </tr>
        <tr th:if="${#lists.isEmpty(array)}">
            <td colspan="5">没有相关信息</td>
        </tr>
        </tbody>
    </table>
</div>
</body>
<script type="text/javascript">
    function loadSuccess() {
        uploadRender({
            elem: '#import',
            accept: 'file',
            data: {},
            multiple: false,
            exts: 'bat|sh',
            acceptMime: '.bat,.sh',
            url: './upload',
            done: function (res, index, upload) {
                layer.msg(res.msg);
                setTimeout(function () {
                    location.reload();
                }, 2000);
            }
        });
    }

    function editItem(t) {
        var id = $(t).attr("sId");
        layerOpen({
            type: 2,
            title: '管理脚本模板',
            shade: 0.8,
            area: ['80%', '90%'],
            content: 'item.html?id=' + id
        });
    }

    function runScript(t) {
        var id = $(t).attr("sId");
        tabChange({
            id: "runScript-" + id,
            url: './script/console.html?id=' + id,
            title: id + '控制台',
        });
    }
</script>
</html>